//
//  BirthdayTimeOffsetTableViewCell.swift
//  FearfulNotification
//
//  Created by 筱鹏 on 2019/6/11.
//  Copyright © 2019 筱鹏. All rights reserved.
//

import UIKit

class BirthdayTimeOffsetTableViewCell: UITableViewCell {

    var titleLabel: UILabel!
    var selectedImageView: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        setupSubviews()
    }
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupSubviews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupSubviews() {
        backgroundColor = Theme.color.background
        contentView.backgroundColor = Theme.color.background
        selectionStyle = .none
        
        titleLabel = UILabel(frame: self.bounds)
        titleLabel.font = Theme.font.date
        titleLabel.textColor = Theme.color.foreground
        contentView.addSubview(titleLabel)
        
        selectedImageView = UIImageView(image: UIImage.circle(stroke: Theme.color.foreground, radius: 10),
                                        highlightedImage: UIImage.circle(fill: Theme.color.foreground, radius: 10))
        selectedImageView.contentMode = .center
        contentView.addSubview(selectedImageView)
        
        titleLabel.translatesAutoresizingMaskIntoConstraints = false
        selectedImageView.translatesAutoresizingMaskIntoConstraints = false
        
        NSLayoutConstraint(item: titleLabel!, attribute: .left, relatedBy: .equal, toItem: contentView, attribute: .left, multiplier: 1.0, constant: 15).isActive = true
        NSLayoutConstraint(item: titleLabel!, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
        NSLayoutConstraint(item: titleLabel!, attribute: .bottom, relatedBy: .equal, toItem: contentView, attribute: .bottom, multiplier: 1.0, constant: 0).isActive = true
        NSLayoutConstraint(item: selectedImageView!, attribute: .left, relatedBy: .equal, toItem: titleLabel, attribute: .right, multiplier: 1.0, constant: 0).isActive = true
        NSLayoutConstraint(item: selectedImageView!, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1.0, constant: 0).isActive = true
        NSLayoutConstraint(item: selectedImageView!, attribute: .right, relatedBy: .equal, toItem: contentView, attribute: .right, multiplier: 1.0, constant: -15).isActive = true
        NSLayoutConstraint(item: selectedImageView!, attribute: .top, relatedBy: .equal, toItem: contentView, attribute: .top, multiplier: 1.0, constant: 0).isActive = true
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        selectedImageView.isHighlighted = selected
        // Configure the view for the selected state
    }

}
